package com.jh.channel.pojo.fastsilver;


import cn.jh.common.core.domain.EnumValue;
import cn.jh.common.core.domain.TextValue;
import cn.jh.common.core.i18n.I18n;
import org.jetbrains.annotations.Contract;

import java.util.Locale;
import java.util.Objects;

import static com.google.common.base.Strings.isNullOrEmpty;

public enum  OrderType implements EnumValue<Short>, TextValue<String, Short> {

    /** 微信 */
    WEIXIN("weixin", "\u5fae\u4fe1"),

    /** 支付宝 */
    ALIPAY("alipay", "\u652f\u4ed8\u5b9d"),
    ;

    final String i18nCode;
    final String defaultText;

    OrderType(String i18nCode, String defaultText) {
        this.i18nCode = i18nCode;
        this.defaultText = defaultText;
    }

    @Override
    public String getText() {
        return getText(Locale.getDefault());
    }

    public String getText(Locale locale) {
        return I18n.getOrDefault(i18nCode, locale, defaultText);
    }

    @Override
    @Contract(pure = true)
    public Short getValue() {
        return (short) ordinal();
    }

    @Contract(pure = true)
    public String getI18nCode() {
        return i18nCode;
    }

    @Contract(pure = true)
    public String getDefaultText() {
        return defaultText;
    }

    public static OrderType of(String val) {
        return of(val, null);
    }

    public static OrderType of(String val, OrderType defaultStatus) {
        if (isNullOrEmpty(val)) {
            return defaultStatus;
        }
        for (OrderType os : values()) {
            if (val.equals(os.getI18nCode())) {
                return os;
            }
        }
        return defaultStatus;
    }



}
